package com.fattyCorps.common.util;

import com.fattyCorps.common.obj.dto.DItemConsume;

import java.util.ArrayList;
import java.util.List;

public class GameCfgUtils {

    public static List<Integer> splitIdListStr(String strList) {
        List<Integer> ids = new ArrayList<>();
        if (strList == null || strList.length() == 0) {
            return ids;
        }

        String[] split = strList.split(",");

        for (String s : split) {
            ids.add(Integer.parseInt(s));
        }

        return ids;
    }

    public static List<DItemConsume> splitItemStr(String strList) {
        List<DItemConsume> retList = new ArrayList<>();
        if (strList == null || strList.length() == 0) {
            return retList;
        }

        String[] split = strList.split(",");

        DItemConsume item = null;
        for (int i = 0; i < split.length; i++) {
            if (i % 2 == 0) {
                item = new DItemConsume();
                item.setTypeId(Integer.valueOf(split[i]));
            } else {
                item.setNum(Integer.valueOf(split[i]));
                retList.add(item);
            }
        }

        return retList;
    }
}
